<%--
  Created by IntelliJ IDEA.
  User: 潘达
  Date: 2020/4/10
  Time: 15:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>代理商管理系统</title>
    <link rel="stylesheet" type="text/css" href="../static/css/public.css">
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
    <div class="head">
        <ul>
            <li><h2>AgentSystem</h2>
            <li class="headfunc"></li>
        </ul>
    </div>
    <div id="menu"></div>
    <div class="container">
        <h2>修改信息</h2>
        <form id="form">
            <ul class="loginul" id="body">
                <li>用户ID：<input type="text" id="id" name="id" readonly/></li>
                <li>登录账号：<input type="text" id="usercode" name="userCode"/></li>
                <li>登录密码：<input type="password" id="userpassword" name="userPassword"/></li>
                <li>用户名称：<input type="text" name="userName"/></li>
            </ul>
            <input type="button" value="提交修改" name="submit"/>
            <input type="button" value="返回" name="return">
        </form>
    </div>
</body>
<script type="text/javascript" src="../static/js/jquery-3.4.0.js"></script>
<script type="text/javascript">
    var id = ${sessionScope.loginer.id};
    $(function () {
        $(function () {
            $.ajax({
                url:"http://localhost:8080/user/getUserById",
                data:{"id":id},
                type:"post",
                success:function (data) {
                    $("input[name='id']").attr("value",data.id);
                    $("input[name='userCode']").attr("value",data.userCode);
                    $("input[name='userPassword']").attr("value",data.userPassword);
                    $("input[name='userName']").attr("value",data.userName);
                },
                dataType:"json"
            });
        });
        $(function () {
            $("input[name='submit']").click(function () {
                var data = $("#form").serialize();
                $.ajax({
                    url:"http://localhost:8080/user/modifyUser",
                    data:data,
                    type:"post",
                    success:function (data) {
                        if(data == "success"){
                            alert("修改成功");
                        }else {
                            alert("修改出错");
                        }
                    },
                    dataType:"json"
                });
            });
        });
    });
</script>
</html>
